<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar title="公告列表" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		
		
		<view v-for="(item,index) in list" :key="index">
			
			<view class="flex-col notice-item" @click="itemClick(item)">
				<view style="font-size: 30rpx;">{{item.title}}</view>
				<view style="color: #999;margin-top: 15rpx;font-size: 28rpx;">{{item.create_date}}</view>
			</view>
			<u-loadmore margin-top="20" margin-bottom="20" :status="status" icon-type="flower"
				:load-text="loadText" />
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
				list:[]
			};
		},
		onLoad() {
			
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		onShow() {
			this.list = [];
			this.page = 1;
			this.getNoticeList();
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.getNoticeList();
		},
		onReachBottom() {
			this.getNoticeList();
		},
		methods:{
			itemClick(item){
				uni.navigateTo({
					url:'/pages/notice/notice_detail?title=' + item.title + '&content=' + encodeURIComponent(item.content)
				})
			},
			getNoticeList(){
				this.$request({
					url:'?c=Index&a=noticeList',
					type:'post',
					data:{
						page:this.page,
						limit:10
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
	// background-color: #F5F5F5;
}
.notice-item{
	background-color: #fff;
	border-radius: 10rpx;
	padding: 20rpx;
	margin: 10rpx 20rpx;
}
</style>
